<!--
 * @description  : 市管-无证查询列表展示页面
 * @descriptionDetail: 市管-无证查询列表展示页面
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-12-06 11:06:12
-->
<template>
	<view class="page">
		<!-- #ifdef H5-ONLY -->
		<theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
		</theme-navbar>
		<!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		<fab-button :content="fContent" @fabtrigger="fabtrigger" />
		<!-- #endif -->
		<view class="content u-page">
			<view class="u-tabs-box">
				<u-tabs :list="tabList" :active-color="$theme.u_type_primary" font-size="20" :is-scroll="false" :current="currentTab" @change="changeTab"></u-tabs>
			</view>
			<!-- 基础信息 -->
			<view v-show="currentTab==0">
				<view style="width: 100%;padding-left: 30rpx; padding-right: 30rpx;" class="first-top">
					<u-form :error-type="errorType" :model="form" label-width="auto" label-position="left" ref="uForm">
						<view style="width: calc(100% - 30px);">
							<form-section title="证照信息"></form-section>
						</view>
						<u-form-item :required="true" label-position="top" label="经营场所地址坐标（X、Y）" prop="longLat">
							<u-input type="text" :needValid="true" :border="ifborder" placeholder="请选择无证户位置" v-model="form.longLat" />
							<u-icon name="map-fill" :color="$theme.u_type_primary" size="44" @click="setLocation()"></u-icon>
						</u-form-item>

						<u-form-item :required="true" label-position="top" label="企业（字号）名称" prop="companyName">
							<u-input type="text" :border="ifborder" placeholder="请输入企业（字号）名称（必填）" v-model="form.companyName" />
						</u-form-item>

						<u-form-item label-position="top" label="经营场所地址" prop="businessAddr">
							<u-input type="textarea" :auto-height="true" :border="ifborder" placeholder="请输入经营场所地址" v-model="form.businessAddr" />
						</u-form-item>

						<u-form-item label="场所邮编">
							<u-input input-align="right" type="number" :border="ifborder" placeholder="请输入邮编号码" v-model="form.postcode" />
						</u-form-item>

						<u-form-item label="所属片区" :required="true" prop="orgName">
							<u-select :list="orgList" mode="single-column" v-model="orgShow" @confirm="selectConfirm"></u-select>
							<u-input :disabled="true" placeholder="请选择片区" v-model="form.orgName" input-align="right" @click="orgShow = true" />
							<!-- 组织机构选择 -->
							<u-popup mode="bottom" height="80%" v-model="selectShowControl.orgNameSelectShow">
								<org-select :cleanParentOrg="true" limitNodeType="07" tips="请选择片区" @choose="orgNameSelectShowComfir"></org-select>
							</u-popup>
						</u-form-item>
						<u-form-item label="工商营业执照" prop="businessLicNo">
							<u-input input-align="right" :border="ifborder" placeholder="请输入工商营业执照" v-model="form.businessLicNo" />
						</u-form-item>
						<u-form-item label="是否曾申办证">
							<view style="width: 100%;display: flex; flex-direction: row;justify-content: flex-end;">
								<u-switch v-model="form.isApplyLic"></u-switch>
							</view>
						</u-form-item>
						<u-form-item label="未办证原因">
							<dic-input :keyWord="$u.dic.DIC_KEYS.REASON" :dicCode="form.unlicenseReason" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('reason',$u.dic.DIC_KEYS.REASON)" placeholder="请选择" :disabled="isDisabled" v-model="form.unlicenseReasonName" @changeInputModelData="(name)=>{$set(form, 'unlicenseReasonName', name)}" @click="showDic($u.dic.DIC_KEYS.REASON,form.unlicenseReason,'reason')" />
						</u-form-item>

						<u-form-item label="是否公开买卖" prop="isOnsale">
							<view style="width: 100%;display: flex; flex-direction: row;justify-content: flex-end;">
								<u-switch v-model="form.isOnsale"></u-switch>
							</view>
						</u-form-item>

						<u-form-item :required="true" label="经营状态" prop="licStatus">
							<dic-input :keyWord="$u.dic.DIC_KEYS.L_UNLICENSE_LICSTATUS" :dicCode="form.licStatus" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('licStatus',$u.dic.DIC_KEYS.L_UNLICENSE_LICSTATUS)" placeholder="请选择" :disabled="isDisabled" v-model="form.licStatusName" @changeInputModelData="(name)=>{$set(form, 'licStatusName', name)}" @click="showDic($u.dic.DIC_KEYS.L_UNLICENSE_LICSTATUS,form.licStatus,'licStatus')" />
						</u-form-item>

						<u-form-item label="零售业态">
							<dic-input :keyWord="$u.dic.DIC_KEYS.FORMAT" :dicCode="form.bizFormat" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('bizFormat',$u.dic.DIC_KEYS.FORMAT)" placeholder="请选择" :disabled="isDisabled" v-model="form.bizFormatName" @changeInputModelData="(name)=>{$set(form, 'bizFormatName', name)}" @click="showDic($u.dic.DIC_KEYS.FORMAT,form.bizFormat,'bizFormat')" />
						</u-form-item>

						<u-form-item label="地区类别">
							<dic-input :keyWord="$u.dic.DIC_KEYS.AREA_TYPE" :dicCode="form.areaType" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('areaType',$u.dic.DIC_KEYS.AREA_TYPE)" placeholder="请选择" :disabled="isDisabled" v-model="form.areaTypeName" @changeInputModelData="(name)=>{$set(form, 'areaTypeName', name)}" @click="showDic($u.dic.DIC_KEYS.AREA_TYPE,form.areaType,'areaType')" />
						</u-form-item>

						<u-form-item label="地理环境">
							<dic-input :keyWord="$u.dic.DIC_KEYS.RETAILER_ENV_TYPE" :dicCode="form.envType" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('envType',$u.dic.DIC_KEYS.RETAILER_ENV_TYPE)" placeholder="请选择" :disabled="isDisabled" v-model="form.envTypeName" @changeInputModelData="(name)=>{$set(form, 'envTypeName', name)}" @click="showDic($u.dic.DIC_KEYS.RETAILER_ENV_TYPE,form.envType,'envType')" />
						</u-form-item>

						<u-form-item label="经营场地权属">
							<dic-input :keyWord="$u.dic.DIC_KEYS.RETAILER_GROUND_OWNERSHIP" :dicCode="form.groundOwnership" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('groundOwnership',$u.dic.DIC_KEYS.RETAILER_GROUND_OWNERSHIP)" placeholder="请选择" :disabled="isDisabled" v-model="form.groundOwnershipName" @changeInputModelData="(name)=>{$set(form, 'groundOwnershipName', name)}" @click="showDic($u.dic.DIC_KEYS.RETAILER_GROUND_OWNERSHIP,form.groundOwnership,'groundOwnership')" />
						</u-form-item>
						<u-form-item label="经营面积(平方米)" prop="bizArea">
							<u-input type="number" input-align="right" :border="ifborder" placeholder="请输入经营面积(平方米)" v-model="form.bizArea" />
						</u-form-item>
						<u-form-item label="租金（元/年）" prop="rent">
							<u-input type="number" input-align="right" :border="ifborder" placeholder="请输入租金" v-model="form.rent" />
						</u-form-item>
						<u-form-item :required="true" label="无证户来源" prop="source">
							<dic-input :keyWord="$u.dic.DIC_KEYS.L_UNLICENSE_SOURCE" :dicCode="form.source" :border="ifborder" inputAlign="right" type="select" :select-open="dicSelectOpen('source',$u.dic.DIC_KEYS.L_UNLICENSE_SOURCE)" placeholder="请选择" :disabled="isDisabled" v-model="form.sourceName" @changeInputModelData="(name)=>{$set(form, 'sourceName', name)}" @click="showDic($u.dic.DIC_KEYS.L_UNLICENSE_SOURCE,form.source,'source')" />
						</u-form-item>
						<view style="margin: 0px -16px;">
							<u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
						</view>
						<view style="width: calc(100% - 30px);">
							<form-section title="经营人信息"></form-section>
						</view>
						<u-form-item label="负责人（经营者）名称" prop="managerName">
							<u-input type="text" input-align="right" :border="ifborder" placeholder="请输入名称" v-model="form.managerName" />
						</u-form-item>
						<u-form-item label="身份证号" prop="managerCredNum">
							<u-input type="text" input-align="right" :border="ifborder" placeholder="请输入证件号码" v-model="form.managerCredNum" />
						</u-form-item>
						<u-form-item label="联系电话" prop="retailTel">
							<u-input type="number" input-align="right" :border="ifborder" placeholder="请输入联系电话" v-model="form.retailTel" />
						</u-form-item>
						<u-form-item label="籍贯" prop="managerLocalName">
							<u-input type="select" input-align="right" :border="ifborder" placeholder="请选择" v-model="form.managerLocalName" @click="selectShowControl.nativeNameSelectShow = true" />
							<!-- 行政区划选择 -->
							<u-popup mode="bottom" height="80%" v-model="selectShowControl.nativeNameSelectShow">
								<area-select @choose="nativeNameSelectShowComfir"></area-select>
							</u-popup>
						</u-form-item>
						<u-form-item label-position="top" label="现居地" prop="currentAddr">
							<u-input type="text" :border="ifborder" placeholder="请输入现居地" v-model="form.currentAddr" />
						</u-form-item>
					</u-form>
				</view>
			</view>
			<!-- 照片信息 -->
			<view v-show="currentTab==1">
				<!-- 图片上传 -->
				<view class="card first-top">
					<h5 class="cardTile">
						店面照片
					</h5>
					<view class="infoContener">
						<view class="card-content-inner photo-container">
							<m-upload index="2" :fileList="storeImagesList" :deletable="true" :maxCount="picIds" width="150rpx" height="150rpx" :multiple="true" upApiUrl="uploadBase64ForApp" :uploadParam="{'fiGroupCode': $FILE_GROUP_TYPE.m_unlicense_attr}" @on-list-change="getImgs">
							</m-upload>
						</view>
					</view>
				</view>
				<view class="line-view-weight"></view>
				<view class="card">
					<h5 class="cardTile">
						柜台照片
					</h5>
					<view class="infoContener">
						<view class="card-content-inner photo-container">
							<m-upload index="3" :fileList="counterImagesList" :deletable="true" :maxCount="picIds" width="150rpx" height="150rpx" :multiple="true" upApiUrl="uploadBase64ForApp" :uploadParam="{'fiGroupCode': $FILE_GROUP_TYPE.m_unlicense_attr}" @on-list-change="getImgs">
							</m-upload>
						</view>
					</view>
				</view>
				<view class="line-view-weight"></view>
				<view class="card">
					<h5 class="cardTile">
						持证人照片
					</h5>
					<view class="infoContener">
						<view class="card-content-inner photo-container">
							<m-upload index="1" :fileList="managerImgsList" :deletable="true" :maxCount="picIds" width="150rpx" height="150rpx" :multiple="true" upApiUrl="uploadBase64ForApp" :uploadParam="{'fiGroupCode': $FILE_GROUP_TYPE.m_unlicense_attr}" @on-list-change="getImgs">
							</m-upload>
						</view>
					</view>
				</view>
			</view>
			<!-- 人员信息 -->
			<view v-show="currentTab==2">
				<view class="card relativecard first-top">
					<view style="width: 100%;align-items: center;display: inline-flex; flex-direction: row; justify-content: space-between;">
						<text class="cardTile">
							从业人员
						</text>
						<u-icon name="plus-circle-fill" size="50" style="margin-right:5px;" :color="$theme.u_type_primary" @click="addPerson()">
						</u-icon>
					</view>
					<view class="infoContener">
						<u-row class="info-row u-p-l-10 u-p-r-15" v-for="(person,index) in persons" :key="index">
							<u-col :span="9">
								<view class="realationView u-p-l-6">
									{{ person.personName }}
									<text class="u-p-l-20" style="font-size: 16px;">
										关系：
									</text>{{ $u.dic.getDicNameByKeyCode($u.dic.DIC_KEYS.L_RELATIONSHIP,person.relationship) ||"" }}
								</view>
							</u-col>
							<u-col :span="3" style="text-align:right;">
								<text class="c-blue u-p-r-30" @click="addPerson(person)">
									编辑
								</text>
								<text class="c-red" @click="delPerson(person)">
									删除
								</text>
							</u-col>
						</u-row>
					</view>
				</view>
			</view>
			<!-- 仓储信息 -->
			<view v-show="currentTab==3">
				<view class="card relativecard first-top">
					<view style="width: 100%;align-items: center;display: inline-flex; flex-direction: row; justify-content: space-between;">
						<text class="cardTile">
							仓储信息
						</text>
						<u-icon name="plus-circle-fill" size="50" style="margin-right:5px;" :color="$theme.u_type_primary" @click="addStorage()">
						</u-icon>
					</view>
					<view class="infoContener">
						<u-row class="info-row u-p-l-10 u-p-r-15" v-for="(storage,index) in storageList" :key="index">
							<u-col :span="8">
								<view class="realationView u-p-l-8">
									{{ storage.storageName }}
								</view>
								<view class="nameView u-p-l-8">
									{{ storage.storageAddress }}
								</view>
							</u-col>
							<u-col :span="2" style="text-align:right;">
								<text class="c-blue" @click="addStorage(storage)">
									编辑
								</text>
							</u-col>
							<u-col :span="2" style="text-align:right;">
								<text class="c-red" @click="delStorage(storage)">
									删除
								</text>
							</u-col>
						</u-row>
					</view>
				</view>
			</view>
			<!-- 关联经营户 -->
			<view v-show="currentTab==4">
				<view class="card relativecard first-top">
					<view style="width: 100%;align-items: center;display: inline-flex; flex-direction: row; justify-content: space-between;">
						<text class="cardTile">
							关联经营户
						</text>
						<u-icon name="plus-circle-fill" size="50" style="margin-right:5px;" :color="$theme.u_type_primary" @click="addRelRetailer()">
						</u-icon>
					</view>
					<view class="infoContener" v-for="(relRetail,index) in relRetailerList" :key="index">
						<view class="supplyItem">
							<u-row style="width:100%;" class="u-p-l-10 u-p-r-15">
								<u-col span="8">
									<text>
										{{ relRetail.companyName }}
									</text>
								</u-col>
								<u-col span="2" text-align="right">
									<text class="c-blue" @click="addRelRetailer(relRetail)">
										编辑
									</text>
								</u-col>
								<u-col span="2" text-align="right">
									<text class="c-red" @click="delRelRetailer(relRetail)">
										删除
									</text>
								</u-col>
							</u-row>
						</view>
					</view>
				</view>
			</view>
			<!-- 货源来源 -->
			<view v-show="currentTab==5">
				<view class="card relativecard first-top">
					<view style="width: 100%;align-items: center;display: inline-flex; flex-direction: row; justify-content: space-between;">
						<text class="cardTile">
							货源来源
						</text>
						<u-icon name="plus-circle-fill" size="50" style="margin-right:5px;" :color="$theme.u_type_primary" @click="addSupply()">
						</u-icon>
					</view>
					<view class="infoContener" v-for="(supply,index) in supplySources" :key="index">
						<view class="supplyItem">
							<u-row class="u-p-l-10 u-p-r-15" style="width:100%">
								<u-col span="10">
									<text>
										{{ supply.companyName }}
									</text>
								</u-col>
								<u-col span="2" text-align="right">
									<text class="c-red" @click="delSupply(supply)">
										删除
									</text>
								</u-col>
							</u-row>
						</view>
					</view>
				</view>
			</view>
			<view class="space-content"></view>
			<view class="submit-btns btn-other-cls">
				<!-- 保存基本信息 -->
				<u-button v-if="currentTab == '0'" class="del" style="width: 99%;" type="primary" size="medium" @click="confirm">
					保存
				</u-button>
				<!-- 保存图片信息 -->
				<u-button v-if="currentTab == '1'" class="del" style="width: 99%;" type="primary" size="medium" @click="saveUnlicenseFile">
					保存
				</u-button>
			</view>
			<view class="bottomSpace">
			</view>
			<!-- 下拉选择用 -->
			<dic-choice :keyWord="dicKeyWords" :currentSelect="dicCurrentSelect" v-model="dicShow" @confirm="selectDicConfirm"></dic-choice>
		</view>
	</view>
</template>

<script>
	import OrgSelect from "@/components/org-select.vue"
	import areaSelect from "@/components/area-select.vue"
	import DicChoice from "@/components/dic_choice.vue"
	import DicInput from "@/components/dic_input.vue"
	import mUpload from "@/components/m-upload.vue"
	import queryService from "@/service/check/query.service";
	import zjCommonService from "@/service/common/common.service";
	import FormSection from "@/components/form-section.vue";
	import checkService from "@/service/check/check.service";
	import {
		M_TASK_SOURCE,
	} from "@/service/check/mapping/enum.js";
	import {
		PATHROOT,
	} from "@/common/path.config";
	import fabButton from '@/components/uni-fab.vue';

	export default {
		components: {
			OrgSelect,
			areaSelect,
			DicChoice,
			DicInput,
			mUpload,
			FormSection,
			fabButton
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		data() {
			return {
				M_TASK_SOURCE,
				fileRoot: PATHROOT.BASE + "/commonfile/filestore/downloadFile.do",
				dicType: "",
				errorType: ['border-bottom', 'message', ],
				// dic_select 是否显示
				dicShow: false,
				// dic 关键字
				dicKeyWords: "",
				// dic 当前选择项
				dicCurrentSelect: "",
				isDisabled: true,
				// 输入框是否有border
				ifborder: false,
				// 权限控制
				readonly: false,
				// 定位图标图片
				// 经营者照片List(此数据格式暂时为展示效果的自定义格式，后接入上传接口后会以id的形式，然后html部分也将改为baseUrl拼接id的远程URL回显)
				managerImgsList: [],
				// 经营者照片List(此数据格式暂时为展示效果的自定义格式，后接入上传接口后会以id的形式，然后html部分也将改为baseUrl拼接id的远程URL回显)
				storeImagesList: [],
				// 经营者照片List(此数据格式暂时为展示效果的自定义格式，后接入上传接口后会以id的形式，然后html部分也将改为baseUrl拼接id的远程URL回显)
				counterImagesList: [],
				// 表单信息(暂无数据接口)
				form: {
					// 经营场所地址坐标（X、Y）
					longLat: '',
					// 企业（字号）名称
					companyName: '',
					// 经营场所地址
					businessAddr: '',
					// 邮编
					postcode: '',
					// 所属片区
					orgName: '',
					// 所属片区uuid
					orgUuid: '',
					// 行政区划
					areaName: '',
					// 是否曾办证
					isApplyLic: false,
					// 为办证原因
					unlicenseReason: '',
					// 为办证原因text
					unlicenseReasonName: '',
					// 是否公开拍卖
					isOnsale: false,
					// 经营状态
					licStatus: '',
					// 经营状态text
					licStatusName: '',
					// 零售业态
					bizFormat: '',
					// 零售业态text
					bizFormatName: '',
					// 地区类型
					areaType: '',
					// 地区类型text
					areaTypeName: '',
					// 地理环境
					envType: '',
					// 地理环境text
					envTypeName: '',
					// 经营场地权属
					groundOwnership: '',
					// 经营场地权属text
					groundOwnershipName: '',
					source: '',
					sourceName: '',
					// 租金
					rent: '',
					// 负责人
					managerName: '',
					// 证件号码
					managerCredNum: '',
					// 籍贯
					managerLocal: '',
					managerLocalName: '',
					currentAddr: '',
					// 联系电话
					retailTel: '',
					// 工商营业执照
					businessLicNo: '',
				},
				// 从业人员（暂时为模拟数据，后根据接口调整数据结构）
				persons: [],
				// 供货来源
				supplySources: [],
				// 下拉显示隐藏控制
				selectShowControl: {
					// 控制片区控制
					orgNameSelectShow: false,
					// 行政区划控制
					areaNameSelectShow: false,
					// 未办证原因控制
					unlicenseReasonSelectShow: false,
					// 营业状态控制
					licStatusSelectShow: false,
					// 零售业态控制
					bizFormatSelectShow: false,
					// 地区类型控制
					areaTypeSelectShow: false,
					// 商圈控制
					busiTypeSelectShow: false,
					// 地理类型控制
					envTypeSelectShow: false,
					// 经营场地权属控制
					groundOwnershipSelectShow: false,
					// 经营人性别控制
					managerGenderSelectShow: false,
					// 证件类型控制
					managerCredTypeSelectShow: false,
					// 籍贯控制
					nativeNameSelectShow: false,
				},
				rules: {
					longLat: [{
						required: true,
						trigger: ['blur', 'change', ],
						message: '请选择无证户位置',
					}, ],
					companyName: [{
						required: true,
						trigger: ['blur', 'change', ],
						message: '请输入',
					}, ],
					orgName: [{
						required: true,
						trigger: ['blur', 'change', ],
						message: '请选择',
					}, ],
					licStatus: [{
						required: true,
						trigger: ['blur', 'change', ],
						message: '请选择',
					}, ],
					source: [{
						required: true,
						trigger: ['blur', 'change', ],
						message: '请选择',
					}, ],
					retailTel: [{
						validator: (rule, value, callback) => {
							if (!this.$u.test.isEmpty(value)) {
								return this.$u.test.mobile(value);
							} else {
								return true;
							}
						},
						message: '请输入正确的手机号码',
						trigger: ['change', 'blur', ],
					}, ],
					businessLicNo: [{
						validator: (rule, value, callback) => {
							if (!this.$u.test.isEmpty(value)) {
								return this.$u.test.enOrNum(value);
							} else {
								return true;
							}
						},
						message: '工商营业执照格式不正确',
						trigger: ['change', 'blur', ],
					}, ],
				},
				tabList: [{
					name: "基础信息",
				}, {
					name: "照片信息",
				}, {
					name: "人员信息",
				}, {
					name: "仓储信息",
				}, {
					name: "关联经营户",
				}, {
					name: "货源来源",
				}, ], // tab栏目
				currentTab: 0,
				picIds: 20,
				storageList: [],
				relRetailerList: [],
				isAddTempTask: false, // 是否检查添加无证户临时任务
				taskSource: '',
				taskSourceItem: '',
				areaUuidList: [],
				areaNameList: [],
				orgList: [],
				orgShow: false,
				fContent: [{
					iconPath: require('@/static/confirm.png'),
					selectedIconPath: require('@/static/confirm.png'),
					text: '确定',
					active: false,
				}],
			};
		},
		created() {},
		onLoad(opt) {
			let obj = this.getRouteParam();
			this.areaUuidList = obj.areaOrgUuids.split(',');
			this.areaNameList = obj.polygonArea.split(',');
			for (let i = 0; i < this.areaUuidList.length; i++) {
				for (let s = 0; s < this.areaUuidList.length; s++) {
					if (i == s) {
						this.orgList.push({
							value: this.areaUuidList[i],
							label: this.areaNameList[i],
						})
					}
				}
			}
			this.form.orgName = this.orgList[0].label;
			this.form.orgUuid = this.orgList[0].value;
			this.isAddTempTask = opt.isAddTempTask;
			this.taskSource = opt.taskSource ? opt.taskSource : '';
			this.taskSourceItem = opt.taskSourceItem ? opt.taskSourceItem : '';
			this.form.licStatusName = "无证经营中";
			this.form.licStatus = "01";
		},
		mounted() {
			this.setRightBtns();
		},
		methods: {

			changeTab(index) {
				// this.currentTab = index;
				if (this.form.retailerUuid) {
					this.currentTab = index;
				} else {
					this.$u.toast("请先保存基础信息！");
					return;
				}
			},
			selectConfirm(e) {
				this.form.orgName = e[0].label;
				this.form.orgUuid = e[0].value;
			},
			initData(obj) {
				queryService.getUnlicenseInfo(obj.retailerUuid).then(dr => {
					this.form = dr.bean;
					Promise.all([
						zjCommonService.orgTree(dr.bean.orgUuid, 'zm-pq'),
						zjCommonService.getAreaByCountryCode(dr.bean.areaCode),
						zjCommonService.getAreaByCountryCode(dr.bean.personLocal),
						queryService.getPersonInfo(dr.bean.retailerUuid),
						zjCommonService.getBscCodes('UNLICENSE_RELATION_PERSON'),
						queryService.getSelectedSource(dr.bean.retailerUuid),
						zjCommonService.getFiles(dr.bean.retailerUuid),
					]).then(res => {
						this.form.orgName = res[0].data[0].name;
						this.persons = res[3].data;
						this.supplySources = res[5].data;
						this.form.areaName = res[1].bean ? (this.$modal.isMuniCity(res[1].bean.proCode) ? [res[1].bean.admdivName, res[1].bean.countryName, ].join("") : [res[1].bean.proName, res[1].bean.admdivName, res[1].bean.countryName, ].join("")) : '';
						this.form.managerLocalName = res[2].bean ? (this.$modal.isMuniCity(res[2].bean.proCode) ? [res[2].bean.admdivName, res[2].bean.countryName, ].join("") : [res[2].bean.proName, res[2].bean.admdivName, res[2].bean.countryName, ].join("")) : '';
						res[3].data.forEach(item => {
							res[4].data.forEach(it => {
								if (item.relationship == it.value) {
									item.relationshipName = it.text;
								}
							})
						})
						res[6].data && res[6].data.forEach(item => {
							item.gfiId = item.gfiUuid;
							if (item.materialType == 'DAWZ0003') {
								this.managerImgsList.push(item);
							} else if (item.materialType == 'DAWZ0001') {
								this.storeImagesList.push(item);
							} else {
								this.counterImagesList.push(item);
							}
						})
					});
					this.form.managerGender = this.form.personType;
					this.form.managerCredType = '01';
					this.form.managerCredNum = this.form.credNum;
					this.form.managerCredAddr = this.form.credAddr;
					if (dr.bean.longitude) {
						this.form.longLat = `${dr.bean.longitude},${dr.bean.latitude}`;
					}
				})
			},
			setRightBtns() {
				// 设置右侧标题
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight("确定", () => {
					this.confirm();
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.confirm();
				}
			},
			dicSelectOpen(type, keyWords) {
				if (type == this.dicType) {
					if (this.dicKeyWords == keyWords && this.dicShow) {
						return true;
					}
					return false;
				}
			},
			showDic(key, cur, type) {
				if (this.dicShow) return;
				if (key == 'L_UNLICENSE_LICSTATUS') return true;
				this.dicKeyWords = key;
				this.dicCurrentSelect = cur;
				this.dicShow = true;
				this.dicType = type;
			},
			/**
			 * @description 下拉选中确定事件，处理选中的结果绑定至数据
			 * @params e 选中的结果数据
			 */
			selectDicConfirm(e) {
				if (this.dicKeyWords == this.$u.dic.DIC_KEYS.REASON) { // 未办证原因
					this.form.unlicenseReasonName = e[0].label;
					this.form.unlicenseReason = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.L_UNLICENSE_LICSTATUS) { // 经营状态
					this.form.licStatusName = e[0].label;
					this.form.licStatus = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.FORMAT) { // 零售业态
					this.form.bizFormatName = e[0].label;
					this.form.bizFormat = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.AREA_TYPE) { // 地区类型
					this.form.areaTypeName = e[0].label;
					this.form.areaType = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.RETAILER_ENV_TYPE) { // 地理环境
					this.form.envTypeName = e[0].label;
					this.form.envType = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.RETAILER_GROUND_OWNERSHIP) { // 经营场地权属
					this.form.groundOwnershipName = e[0].label;
					this.form.groundOwnership = e[0].extra.bcbCode;
				} else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.L_UNLICENSE_SOURCE) { // 无证户来源
					this.form.sourceName = e[0].label;
					this.form.source = e[0].extra.bcbCode;
				}
			},
			personSave(person) {
				this.$u.loading("保存中...");
				queryService.personSave(person).then((rs) => {
					this.$u.hideLoading();
					if (rs.success) {
						this.$u.toast("保存成功！");
						this.queryPersonList();
					}
				}).catch((err) => {
					this.$u.toast(err);
					this.$u.hideLoading();
				});
			},
			personUpdate(person) {
				this.$u.loading("保存中...");
				queryService.personUpdate(person).then((rs) => {
					this.$u.hideLoading();
					if (rs.success) {
						this.$u.toast("修改成功！");
						this.queryPersonList();
					}
				}).catch((err) => {
					this.$u.toast(err);
					this.$u.hideLoading();
				});
			},
			/**
			 * @description 地图选择点位点击确定会触发的函数
			 * @prams data 地理相关信息
			 */
			updateBackState(data) {
				if (data.person) {
					data.person['retailerUuid'] = this.form.retailerUuid;
					data.person['subjectType'] = '02';
					data.person['personType'] = '03';
					if (data.person.personUuid) {
						this.personUpdate(data.person);
					} else {
						this.personSave(data.person);
					}
				} else if (data.storage) {
					data.storage['retailerUuid'] = this.form.retailerUuid;
					data.storage['subjectType'] = '02';
					this.$u.loading("保存中...");
					queryService.storageSaveOrUpdate(data.storage).then((rs) => {
						this.$u.hideLoading();
						if (rs.success) {
							this.$u.toast("保存成功！");
							this.queryStorageList();
						}
					}).catch((err) => {
						this.$u.toast(err);
						this.$u.hideLoading();
					})
				} else if (data['temporaryTask']) {
					let retailerClients = data['temporaryTask'];
					let reUuids = [];
					retailerClients.forEach(c => {
						if (this.supplySources.filter(r => r.retailerUuid == c.retailerUuid).length > 0) {
							this.$u.toast(`【${c.companyName}】已存在`);
							return;
						} else {
							// this.supplySources.push(c);
							reUuids.push(c.retailerUuid);
						}
					});
					this.$u.loading("保存中...");
					queryService.supplySaveOrUpdate({
						"subjectType": "01",
						"unlicenseRetailerUuid": this.form.retailerUuid,
						"retailerUuid": reUuids.join(','),
					}).then((rs) => {
						this.$u.hideLoading();
						if (rs.success) {
							this.$u.toast("保存成功！");
							this.querySupplyList();
						}
					}).catch((err) => {
						this.$u.toast(err);
						this.$u.hideLoading();
					});
				} else if (data['relRetailer']) {
					let retailerClient = data['relRetailer'];
					// 添加执行
					if (!retailerClient.relUuid) {
						if (this.relRetailerList.filter(r => r.relRetailerUuid == retailerClient.retailerUuid).length > 0) {
							this.$u.toast(`【${retailerClient.companyName}】已存在`);
							return;
						}
					}

					let param = {
						relUuid: retailerClient.relUuid || '',
						ownSubjectType: "02",
						ownerRetailerUuid: this.form.retailerUuid,
						relSubjectType: "01",
						relRetailerUuid: retailerClient.retailerUuid,
						relation: retailerClient.relation,
						relRemark: retailerClient.relRemark,
					}
					this.$u.loading("保存中...");
					queryService.saveRelRetailer(param).then((rs) => {
						this.$u.hideLoading();
						if (rs.success) {
							this.$u.toast("保存成功！");
							this.queryRelRetailerList();
						}
					}).catch((err) => {
						this.$u.toast(err);
						this.$u.hideLoading();
					});
				} else {
					// 回显经纬度
					this.form.longLat = `${data.pos.longitude},${data.pos.latitude}`;
					this.form.longitude = data.pos.longitude;
					this.form.latitude = data.pos.latitude;
					// 回显地址
					this.form.businessAddr = data.pos.detailAddress || '-';
					// 回显邮编
					this.form.postcode = data.pos.regeocode.addressComponent.adcode || '-';
				}
			},
			/**
			 * @description 跳转经营场所地址地理信息页面
			 */
			setLocation() {
				this.$u.route('pages/commonPage/modifyLocationMap');
			},
			/**
			 * @description 片区下拉确认事件
			 * @params orgs 组织机构信息
			 */
			orgNameSelectShowComfir(orgs) {
				if (orgs.length == 0) {
					this.$u.toast("请选择片区");
					return;
				}
				this.form.orgUuid = orgs[0].id;
				this.form.orgName = orgs[0].name;
				this.orgSelectShow = false;
				this.selectShowControl.orgNameSelectShow = false;
			},
			/**
			 * @description 行政区划下拉确认事件
			 * @params
			 */
			areaNameSelectShowComfir(areas) {
				if (this.$modal.isMuniCity(areas[0].proCode)) {
					this.form.areaName = [areas[0].proName, areas[0].admdivName, areas[0].countryName, ].join("");
				} else {
					this.form.areaName = [areas[0].proName, areas[0].admdivName, areas[0].countryName, ].join("");
				}
				this.form.areaCode = areas[0].areaCode;
				this.form.prov = areas[0].proCode;
				this.form.city = areas[0].admdivCode;
				this.selectShowControl.areaNameSelectShow = false;
			},
			/**
			 * @description 籍贯下拉确认事件
			 * @params
			 */
			nativeNameSelectShowComfir(areas) {
				if (this.$modal.isMuniCity(areas[0].proCode)) {
					this.form.managerLocalName = [areas[0].admdivName, areas[0].countryName, ].join("");
				} else {
					this.form.managerLocalName = [areas[0].proName, areas[0].admdivName, areas[0].countryName, ].join("");
				}
				this.form.personLocal = areas[0].areaCode;
				this.form.managerLocal = areas[0].areaCode;
				this.$set(this.form, 'local-prov', areas[0].proCode);
				this.$set(this.form, 'local-city', areas[0].admdivCode);
				this.selectShowControl.nativeNameSelectShow = false;
			},
			// 添加供货来源
			addSupply() {
				this.setRouteParam(this.supplySources);
				this.$u.route("/pages/check/temporaryTask?taskSubject=01&title=选择货源来源");
			},
			// 删除供货来源
			delSupply(data) {
				this.$modal.confirm("确定要删除吗？", () => {
					queryService.delSupplySource([data.recordUuid, ]).then((rs) => {
						if (rs.success) {
							this.$u.toast('删除成功！');
							this.querySupplyList();
						}
					})
				});
			},
			// 查询供货来源列表
			querySupplyList() {
				this.$u.loading("加载中...");
				queryService.sourceInfoList({
					"page": 1,
					"limit": 10,
					"unlicenseRetailerUuid": this.form.retailerUuid,
				}).then((dr) => {
					this.$u.hideLoading();
					if (dr.success) {
						this.supplySources = dr.data;
					} else {
						this.$u.toast('查询失败！');
					}
				}).catch((err) => {
					this.$u.toast(err);
					this.$u.hideLoading();
				})
			},
			// 删除从业人员
			delPerson(data) {
				this.$modal.confirm("确定要删除吗？", () => {
					queryService.delPerson(data.personUuid).then((rs) => {
						if (rs.success) {
							this.$u.toast('删除成功！');
							this.queryPersonList();
						}
					});
				});
			},
			// 添加从业人员
			addPerson(person) {
				if (!person) person = {
					uuid: Date.now(),
				};
				person.retailerUuid = this.form.retailerUuid;
				this.setRouteParam(person);
				this.$u.route("/pages/commonPage/employeeAddComponent");
			},
			// 查询从业人员列表
			queryPersonList() {
				let param = {
					personType: '03',
					retailerUuid: this.form.retailerUuid,
				}
				this.$u.loading("加载中...");
				queryService.listPersonFetch(1, 10, param).then((dr) => {
					this.$u.hideLoading();
					if (dr.success) {
						this.persons = dr.data;
					} else {
						this.$u.toast('查询失败！');
					}
				}).catch((err) => {
					this.$u.toast(err);
					this.$u.hideLoading();
				})
			},
			// 添加仓储信息
			addStorage(storage) {
				if (!storage) storage = {
					uuid: Date.now(),
				};
				storage.retailerUuid = this.form.retailerUuid;
				this.setRouteParam(storage);
				this.$u.route("/pages/commonPage/storageAddComponent");
			},
			// 删除仓储信息
			delStorage(data) {
				this.$modal.confirm("确定要删除吗？", () => {
					queryService.delStorage([data.storageUuid, ]).then((rs) => {
						if (rs.success) {
							this.$u.toast('删除成功！');
							this.queryStorageList();
						}
					})
				});
			},
			// 查询仓储信息
			queryStorageList() {
				this.$u.loading("加载中...");
				queryService.findStorageInfoList({
					"page": 1,
					"limit": 10,
					"retailerUuid": this.form.retailerUuid,
				}).then((dr) => {
					this.$u.hideLoading();
					if (dr.success) {
						this.storageList = dr.data;
					} else {
						this.$u.toast('查询失败！');
					}
				}).catch((err) => {
					this.$u.toast(err);
					this.$u.hideLoading();
				})
			},
			// 添加关联经营户
			addRelRetailer(relRetail) {
				this.setRouteParam(relRetail);
				this.$u.route("/pages/commonPage/relRetailerAddComponent");
			},
			// 删除关联经营户
			delRelRetailer(data) {
				this.$modal.confirm("确定要删除吗？", () => {
					queryService.delRelRetailer([data.relUuid, ]).then((rs) => {
						if (rs.success) {
							this.$u.toast('删除成功！');
							this.queryRelRetailerList();
						}
					})
				});
			},
			// 查询关联经营户信息
			queryRelRetailerList() {
				this.$u.loading("加载中...");
				queryService.ListByRetailer(1, 10, {
					retailerUuid: this.form.retailerUuid,
				}).then((dr) => {
					this.$u.hideLoading();
					if (dr.success) {
						this.relRetailerList = dr.data;
					} else {
						this.$u.toast('查询失败！');
					}
				}).catch((err) => {
					this.$u.toast(err);
					this.$u.hideLoading();
				})
			},
			// 上传图片回调事件
			getImgs(e, pos) {
				if (pos == '1') {
					this.managerImgsList = [...e, ];
				} else if (pos == '2') {
					this.storeImagesList = [...e, ];
				} else if (pos == '3') {
					this.counterImagesList = [...e, ];
				}
			},
			// 保存无证户
			confirm() {
				this.$refs.uForm.validate(valid => {
					if (!valid) return;
					let params = {};
					params = {
						...this.form,
					};
					params.isOnsale = params.isOnsale ? "1" : "0";
					params.isApplyLic = params.isApplyLic ? "1" : "0";

					this.$modal.alert("确定要提交吗？", "提醒", () => {
						this.$modal.showLoading("正在保存...");
						// queryService.saveUnlicenseRetailer(unlicenseRetailer).then((dr) => {
						queryService.saveUnlicenseInfo(params).then((dr) => {
							this.$modal.hideLoading();
							if (dr.success) {
								this.$u.toast("无证户保存成功！");
								this.form.retailerUuid = dr.bean.retailerUuid;
								this.isAddTempTask && this.addTempTask();
								// 记录无证户采集操作
								zjCommonService.dingLog(dr.bean.retailerUuid, "cert", "register",
									"无证户采集", `无证户[${this.form.companyName}]`)
							} else this.$u.toast(dr.msg);
						}).catch(err => {
							console.log(JSON.stringify(err) + '=====' + err);
							this.$modal.hideLoading();
							this.$u.toast("保存失败");
						});
					}, '', true);
				});
			},
			// 将无证户添加到检查的临时任务中
			addTempTask() {
				let message = "";
				checkService.addTempClient(this.applyCode, this.form.retailerUuid, this.taskSource, this.taskSourceItem).then(dr => {
					if (dr.success) {
						if (dr.msg) {
							message = dr.msg;
						} else {
							message = '临时任务添加成功！';
						}
						this.$u.toast(message);
					} else {
						this.$u.toast(dr.msg);
					}
				});
			},
			// 保存无证户图片
			saveUnlicenseFile() {
				let fiArr = {
					storeImageList: [],
					counterImageList: [],
					custImageList: [],
				};
				this.managerImgsList.forEach(itm => {
					let objImg = {
						fileId: itm.gfiId,
						gfiId: itm.gfiId,
						name: itm.gfiStoreName,
						size: itm.gfiSize,
						type: 'image/' + itm.gfiSuffix,
						status: "done",
						url: this.fileRoot + '?tk=' + this.curUser.tk + '&fileId=' + itm.gfiId,
					}
					fiArr.custImageList.push(objImg);
				});
				this.storeImagesList.forEach(itm => {
					let stoObjImg = {
						fileId: itm.gfiId,
						gfiId: itm.gfiId,
						name: itm.gfiStoreName,
						size: itm.gfiSize,
						type: 'image/' + itm.gfiSuffix,
						status: "done",
						url: this.fileRoot + '?tk=' + this.curUser.tk + '&fileId=' + itm.gfiId,
					}
					fiArr.storeImageList.push(stoObjImg);
				});
				this.counterImagesList.forEach(itm => {
					let couObjImg = {
						fileId: itm.gfiId,
						gfiId: itm.gfiId,
						name: itm.gfiStoreName,
						size: itm.gfiSize,
						type: 'image/' + itm.gfiSuffix,
						status: "done",
						url: this.fileRoot + '?tk=' + this.curUser.tk + '&fileId=' + itm.gfiId,
					}
					fiArr.counterImageList.push(couObjImg);
				});
				let params = {
					retailerUuid: this.form.retailerUuid,
					storeImageList: fiArr.storeImageList,
					counterImageList: fiArr.counterImageList,
					custImageList: fiArr.custImageList,
				}
				this.$modal.showLoading("正在保存...");
				queryService.saveUnlicenseFile(params).then((dr) => {
					this.$modal.hideLoading();
					if (dr.success) {
						this.$modal.toast("保存成功");
					} else this.$modal.alert(dr.msg);
				}).catch(err => {
					console.log(JSON.stringify(err) + '=====' + err);
					this.$modal.hideLoading();
					this.$modal.alert("保存失败");
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "./scss/addNolicence.scss";

	.page {
		padding: 0;
	}

	.right-icon {
		padding: 0 25rpx;
		font-size: 30rpx;
		color: white;
	}

	.u-tabs-box {
		width: 100%;
		position: fixed;
		z-index: 999;
		/* #ifdef H5-DINGDING  */
		top: 0px;
		/* #endif */
		/* #ifndef H5-DINGDING  */
		top: 45px;
		/* #endif */
	}

	.first-top {
		margin-top: 50px;
	}
</style>
